package com.example.day09_zuoye.frag;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.day09_zuoye.R;
import com.example.day09_zuoye.Rec_Bean;
import com.example.day09_zuoye.adap.Rec_Adapter;
import com.example.day09_zuoye.p.P_Presenter;
import com.example.day09_zuoye.v.V_View;

import java.util.ArrayList;
import java.util.List;

public class ShouYe_Fragment extends Fragment implements V_View {

    private View view;
    private RecyclerView rec;
    private ArrayList<Rec_Bean.DataBean.DatasBean> list;
    private P_Presenter presenter;
    private Rec_Adapter adapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.shouye_layout, null);
        initView(view);
        initRec();

        presenter = new P_Presenter(this);
        presenter.getData();
        return view;
    }

    private void initRec() {
        rec.setLayoutManager(new LinearLayoutManager(getActivity()));
        rec.addItemDecoration(new DividerItemDecoration(getActivity(),1));
        list = new ArrayList<>();
        adapter = new Rec_Adapter(getActivity(), list);
        rec.setAdapter(adapter);
    }

    private void initView(View view) {
        rec = view.findViewById(R.id.Rec);
    }

    @Override
    public void setData(List<Rec_Bean.DataBean.DatasBean> datasBeans) {
        list.addAll(datasBeans);
        adapter.notifyDataSetChanged();
    }

    @Override
    public void showToast(String str) {

    }
}
